package com.sky.factory;

import java.util.Scanner;

/**
 * Created by Frank Lau on 2017/5/26 0026.
 */
public class calculator_1_2 {

    //client-end
    public static void main(String[] args) {
        try {
            Scanner scanner = new Scanner(System.in);
            System.out.println("請輸入數字A: ");
            String A = scanner.nextLine();
            System.out.println("請輸入運算符(+ - * /): ");
            String operator = scanner.nextLine();
            System.out.println("請輸入數字B: ");
            String C = scanner.nextLine();
            String D = String.valueOf(Operator.GetResult(Double.parseDouble(A), Double.parseDouble(C), operator));
            System.out.print(D);
        }
        catch (Exception e) {
            System.err.print("輸入有誤: " + e.getMessage());
        }

    }

    //operator
    private static class Operator {
        static double GetResult(double v, double v1, String operator) {
            double result = 0d;

            switch (operator) {
                case "+":
                    result = v + v1;
                    break;
                case "-":
                    result = v + v1;
                    break;
                case "*":
                    result = v * v1;
                    break;
                case "/":
                    result = v / v1;
                    break;

            }
            return result;
        }
    }
}
